using System.Linq;
using SapaFinance.Domain.Model;
using SapaFinance.GenericRepository;

namespace SapaFinance.Domain.Specifications
{
    public interface IAccountSpecification : ISpecification<Account>
    {
        IAccountSpecification WithCorporation(Corporation corporation);
        IAccountSpecification Active();
    }

    public class AccountQueryableSpecification
     : QueryableSpecification<Account>
       , IAccountSpecification
    {

        public AccountQueryableSpecification(IUnitOfWorkConvertor unitOfWorkConvertor)
            : base(unitOfWorkConvertor)
        {
        }

        public IAccountSpecification WithCorporation(Corporation corporation)
        {
            this.Queryable = this.Queryable.Where(c => c.Corporation.UID == corporation.UID);
            return this;
        }

        public IAccountSpecification Active()
        {
            this.Queryable = this.Queryable.Where(c => !c.IsHidden);
            return this;
        }
    }
}